#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, p[131072], v[131072], cnt[131072], dep[131072], lf[131072], bid[13000];
vector<int> edges[131072];
vector<int> lfs, rfs;
int used[1333];

int ljs(int x, int y) {
	int ans = 0;
	while (x != y) {
		if (dep[x] < dep[y]) swap(x, y);
		ans += v[x];
		x = p[x];
	}
	return ans;
}

void add(int x, int y) {
	while (x != y) {
		if (dep[x] < dep[y]) swap(x, y);
		++bid[x];
		x = p[x];
	}
}
int ANS = 1ll << 60;
void dfs(int i) {
	if (i == lfs.size() + 1) {
		memset(bid, 0, sizeof(bid));
		for (int i = 1; i < rfs.size(); ++i) {
			add(rfs[i], rfs[i - 1]);
		}
		add(rfs[0], 1);
		add(rfs.back(), 1);
		for (int i = 2; i <= n; ++i) {
			if (bid[i] != 2) return;
		}
		int ans = 0;
		for (int i = 1; i < rfs.size(); ++i) {
			ans = max(ans, ljs(rfs[i], rfs[i - 1]));
		}
		ANS = min(ANS, ans);
		return;
	}
	for (auto j : lfs) {
		if (!used[j]) {
			rfs.push_back(j);
			used[j] = 1;
			dfs(i + 1);
			rfs.pop_back();
			used[j] = 0;
		}
	}
}

signed main() {
	freopen("trip.in", "r", stdin); freopen("trip.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	if (n > 100) return 0;
	for (int i = 2; i <= n; ++i) {
		cin >> p[i] >> v[i];
		dep[i] = dep[p[i]] + 1;
		edges[p[i]].push_back(i);
		lf[p[i]] = 1;
	}
	for (int i = 1; i <= n; ++i) {
		if (!lf[i]) lfs.push_back(i);
	}
	dfs(1);
	cout << ANS << "\n";
	return 0;
}
